Skip to content

Conversation

@shatfield4
Copy link
Collaborator

@shatfield4 shatfield4 commented Oct 31, 2025

Pull Request Type

  • ✨ feat
  • πŸ› fix
  • ♻️ refactor
  • πŸ’„ style
  • πŸ”¨ chore
  • πŸ“ docs

Relevant Issues

resolves #4599

What is in this change?

  • Patches Ollama race condition bug (very similar to Fix LM Studio race condition bugΒ #4597)
  • Bug occurs in the constructor when we begin fetching the context windows in the background (using .then in constructor does not wait for completion before instantiating the class) and there is no check to ensure this.limits was initialized before a chat can be sent
  • This race condition bug happens when a user has lots of models in Ollama and the API has a delay in returning the context windows causing the chat to be sent before we can get a response back from the context window Ollama API endpoint (this.limits is not initialized)
  • Adds awaited ensureModelCached guard function to all chat methods and agent provider chat methods to block a chat from happening until we either get a response back from the Ollama API with correct context window OR fallback to 4096 as default context window size (ensures this.limits is initialized properly)
  • Adds checks for models that may have been downloaded from Ollama AFTER the backend server was started and fetches context windows again from the Ollama API if the model is not already cached instead of just defaulting back to 4096 immediately when the selected model doesn't exist in cache
  • Adds test cases for both Ollama LLM and agent providers

Additional Information

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

@shatfield4 shatfield4 self-assigned this Oct 31, 2025
@shatfield4 shatfield4 linked an issue Oct 31, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Ollama race condition bug

2 participants